package work3.student;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * 使用 List 集合实现简易的学生信息管理系统，要求打印字符界面提示用户选择相应的功能
 *
 * */
public class StudentMain {

    public static void main(String[] args){

        //初始化添加学生数据

        //加入文件处理后，不需要先添加学生信息了
        List<StudentInfo> list = new ArrayList<>();
/*        StudentInfo info = null;
        try {
            info = new StudentInfo(1,"张三",18);
            StudentInfo info1 = new StudentInfo(2,"张三",18);
            StudentInfo info2 = new StudentInfo(3,"李四",18);
            StudentInfo info3 = new StudentInfo(4,"王二",18);
            StudentInfo info4 = new StudentInfo(5,"刘伟",18);
            StudentInfo info5 = new StudentInfo(6,"燕三",18);
            StudentInfo info6 = new StudentInfo(7,"诸葛钢铁",18);
            StudentInfo info7 = new StudentInfo(8,"曹操",18);
            StudentInfo info8 = new StudentInfo(9,"孙权",18);
            StudentInfo info9 = new StudentInfo(10,"刘备",18);
            list.add(info);
            list.add(info1);
            list.add(info2);
            list.add(info3);
            list.add(info4);
            list.add(info5);
            list.add(info6);
            list.add(info7);
            list.add(info8);
            list.add(info9);
        } catch (StudentNoException e) {
            e.printStackTrace();
        } catch (AgeException e) {
            e.printStackTrace();
        }*/

        if (null != FileUtils.getListFromFile()){
            list = FileUtils.getListFromFile();
            System.out.println("已成功加载学生信息");
        }

        else
            System.out.println("无学生数据请添加");
        //设置学生信息到处理类中
        StudentModel.setStudentList(list);
        Scanner scanner = new Scanner(System.in);



        int i = 1;
        while (i != 0){
            System.out.println("欢迎使用学生信息管理系统,请选择功能:");

            System.out.println("1:查找学生");
            System.out.println("2:查看所有学生信息");
            System.out.println("3:增加学生");
            System.out.println("4:修改学生信息");
            System.out.println("5:删除学生");
            System.out.println("6:退出系统");

            switch (scanner.nextInt()) {
                case 1:
                    StudentModel.searchStudent();
                    break;
                case 2:
                    StudentModel.printStudentInfo();
                    break;
                case 3:
                    StudentModel.addStudent();
                    break;
                case 4:
                    StudentModel.updateStudentInfo();
                    break;
                case 5:
                    StudentModel.delStudent();
                    break;
                case 6:
                    i = 0;
                    FileUtils.writeInfoToFile(list);
                    System.out.println("谢谢使用，再见");
                    break;
                default:
                    System.out.println("系统无此功能");
                    break;
            }
        }
    }
}
